﻿using UnityEngine;
using Mirror;
using Code.CharacterSystem;

namespace NetTest
{
    public class NetPlayer : NetworkBehaviour
    {
        private GameObject _targetCharacter;

        
        public int index = 0;

        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Space)) 
            {
                Debug.Log("攻击");
            }

            if (Input.GetMouseButtonDown(0))
            {
                SendCommand();
            }
        }
        [Command]
        private void SendCommand()
        {
            Debug.Log("向服务器发送命令");

            transform.Translate(Vector2.right);
        }

        [ServerCallback]
        private void OnTriggerEnter(Collider other)
        {
            Debug.Log(gameObject.name);
            Debug.Log(other.name);
        }

        public override void OnStartAuthority()
        {
            index++;
            Debug.Log("OnStartAuthority"+index);
        }
        public override void OnStartServer()
        {
            index++;
            Debug.Log("OnStartServer"+index);
        }
        public override void OnStartClient()
        {
            index++;
            Debug.Log("OnStartClient"+index);
            var characterMessage=new CreateCharacterMessage
            {
                Character = _targetCharacter,
                Name = "Character1"
            };
            NetworkClient.Send(characterMessage);
        }
        public override void OnStartLocalPlayer()
        {
            index++;
            Debug.Log("OnStartLocalPlayer" + index);
        }
        public override void OnStopAuthority()
        {
            base.OnStopAuthority();
        }

        public override void OnStopClient()
        {
            base.OnStopClient();
        }

        public override void OnStopLocalPlayer()
        {
            base.OnStopLocalPlayer();
        }

        public override void OnStopServer()
        {
            base.OnStopServer();
        }

        protected override void OnValidate()
        {
            base.OnValidate();
        }
    }
}
